<template>
  <div class="my-charts">
    <div id="my_bar_chart"></div>
    <div id="my_pie_chart"></div>
    <!-- <div id="my_line_chart"></div>
    <div id="my_barline_chart"></div> -->
  </div>
</template>

<script>
import * as echarts from "echarts";

export default {
  props: {},
  components: {},
  data() {
    return {
      barChart: null, // 柱状图
      pieChart: null, // 饼图
      lineChart: null, // 折线图
      barLineChart: null // 堆叠折线图
    };
  },
  watch: {},
  computed: {},
  mounted() {
    this.barChart = echarts.init(document.getElementById("my_bar_chart"));
    this.pieChart = echarts.init(document.getElementById("my_pie_chart"));
    // this.lineChart = echarts.init(document.getElementById("my_line_chart"));
    // this.barLineChart = echarts.init(
    //   document.getElementById("my_barline_chart")
    // );
    this.init();
  },
  methods: {
    init() {
      this.barChart.setOption({
        title: {
          text: "销售额",
          textStyle: {
            color: "pink", // 标题颜色
            fontSize: 14, // 默认值：18
            fontStyle: "italic", // normal:正常风格（默认值）,italic:倾斜体
            fontWeight: "bold" // normal:正常粗细（默认值）,bold/bolder:粗体,lighter:正常粗细
          },
          subtext: ""
        },
        grid: {
          left: "40px",
          right: "10px",
          bottom: "30px"
        },
        xAxis: {
          show: true,
          axisTick: {
            show: false,
            length: 20 // 竖线的长度
          },
          data: ["张三", "李四", "王五"]
        },
        yAxis: {
          axisLabel: {
            show: true
          }
        },
        series: [
          {
            name: "访问来源",
            type: "bar", // 设置图表类型为柱状
            data: [
              // 数据数组，name 为数据项名称，value 为数据项值
              { value: 235, name: "张三" },
              { value: 274, name: "李四" },
              { value: 310, name: "王五" }
            ]
          }
        ]
      });
      this.pieChart.setOption({
        title: {
          text: "售出占比"
        },
        series: [
          {
            name: "访问来源",
            type: "pie", // 设置图表类型为饼图
            radius: "50%", // 饼图的半径，外半径为可视区尺寸（容器高宽中较小一项）的 55% 长度。
            data: [
              // 数据数组，name 为数据项名称，value 为数据项值
              { value: 235, name: "张三" },
              { value: 274, name: "李四" },
              { value: 310, name: "王五" }
            ]
          }
        ]
      });
    
     
    }
  }
};
</script>

<style scoped lang="scss">
.my-charts {
  display: flex;
  justify-content: space-around;
  > div {
    width: 250px;
    height: 150px;
   margin-bottom: 30px;
    border: 1px solid #ccc;
  }
  div + div {
    margin-left: 10px;
  }
}
</style>